﻿using QMERP.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace QMERP.Infrastructure.EFCore.Extensions
{
    public static class UserExtension
    {
        public static IQueryable<User> GetByOrganizationId(this IQueryable<User> query, long organizationId)
        {
            var obj = from a in query
                      from b in a.User_Organizations.DefaultIfEmpty()
                      where (b.Organization!.Level != null && ("," + b.Organization!.Level + ",").Contains("," + organizationId + ",")) || b.OrganizationId == organizationId
                      select a;
            return obj.Distinct();

        }
    }
}
